import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router, UrlSegment } from '@angular/router';
import { BreadcrumbData } from 'src/app/components/my-breadcrumb/my-breadcrumb.component';
import { meFunc } from './me-func';

@Component({
  selector: 'app-me',
  templateUrl: './me.component.html',
  styleUrls: ['./me.component.scss']
})
export class MeComponent implements OnInit {
  meFuncs = meFunc
  constructor(
    private router: Router,
    private route: ActivatedRoute
  ) { }

  ngOnInit(): void {
    this.initBreadcrumb()
  }

  initBreadcrumb(){
    this.route.children[0].url.subscribe((res: UrlSegment[]) => {
      this.currentFunc = this.meFuncs.find(_ => _.router.indexOf(res[0].path) > -1)
    })
  }
  
  breadcrumbData: BreadcrumbData[] = []
  currentFunc: any = this.meFuncs[0]
  goNav(nav: any){
    this.breadcrumbData = [
      { title: '个人中心', router: '/me/account' },
      { title: nav.title },
    ]
    this.currentFunc = nav
    this.router.navigate([nav.router])
  }

}
